﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;

namespace WpfAppCap1_L2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            foreach (FontFamily F in Fonts.SystemFontFamilies)
            {
                ListBoxItem l = new ListBoxItem();
                l.Content = F.ToString();
                l.FontFamily = F;
                listbox1.Items.Add(l);
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            richtxt1.Selection.ApplyPropertyValue(FontWeightProperty, FontWeights.Bold);
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            richtxt1.Selection.ApplyPropertyValue(FontStyleProperty, FontStyles.Italic);
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            try
            {
                richtxt1.Selection.ApplyPropertyValue(FontSizeProperty, slider1.Value.ToString());
            }
            catch (Exception ex)
            {

            }
        }

        private void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            richtxt1.Selection.ApplyPropertyValue(FontFamilyProperty, ((ListBoxItem)listbox1.SelectedItem).FontFamily);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            var assembly = Assembly.GetExecutingAssembly();
            var name = assembly.GetManifestResourceNames().SingleOrDefault(x => x.Contains("bob_style.css"));

            var stream = assembly.GetManifestResourceStream(name);
            using (System.IO.StreamReader myReader = new System.IO.StreamReader(stream))
            {
                richtxt1.AppendText(myReader.ReadToEnd());
            }
        }
    }
}
